package com.dhemery.mack.application;


import java.util.List;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import com.dhemery.mack.actions.ActionList;
import com.dhemery.mack.actions.ActionSet;
import com.dhemery.mack.actions.MenuFactory;
import com.dhemery.mack.actions.SaveAction;
import com.dhemery.mack.actions.ShowProjectExplorerAction;

public class MackActionBarAdvisor extends ActionBarAdvisor {
	private ActionSet actionSet = new ActionSet();

	public MackActionBarAdvisor(IActionBarConfigurer configurer) {
        super(configurer);
    }

	private ActionList createFileActions(IWorkbenchWindow window) {
		ActionList actions = new ActionList("&File");
		MackPlugin plugin = MackPlugin.getInstance();
		actions.add(new SaveAction(window, plugin));
		return actions;
	}

	private ActionList createViewActions(IWorkbenchWindow window) {
		ActionList actions = new ActionList("&View");
		MackPlugin plugin = MackPlugin.getInstance();
		actions.add(new ShowProjectExplorerAction(window, plugin));
		return actions;
	}

	@Override
	protected void fillCoolBar(ICoolBarManager coolBar) {
		new MenuFactory().makeToolBars(coolBar, actionSet);
    }

	@Override
	protected void fillMenuBar(IMenuManager menuBar) {
		new MenuFactory().makeMenus(menuBar, actionSet);
    }

	@Override
	protected void makeActions(IWorkbenchWindow window) {
		actionSet = new ActionSet();
		actionSet.add(createFileActions(window));
		actionSet.add(createViewActions(window));
		registerActions(actionSet.getActions());
    }

	private void registerActions(List<IAction> actions) {
		MackPlugin.getInstance().setActions(actions);
		for(IAction action : actions) register(action);
	}
}
